package com.twu.biblioteca.options;

import com.twu.biblioteca.Book;
import com.twu.biblioteca.BookRepository;
import com.twu.biblioteca.Option;
import com.twu.biblioteca.UserInterface;

/**
 * Created with IntelliJ IDEA.
 * User: aulme
 * Date: 01/07/2013
 * Time: 12:54
 * To change this template use File | Settings | File Templates.
 */
public class ReserveBookOption implements Option {
    private UserInterface ui;
    private BookRepository books;

    public ReserveBookOption(UserInterface ui, BookRepository books) {
        this.ui = ui;
        this.books = books;
    }

    @Override
    public String toString() {
        return "Reserve a book (please type in the book's name)";
    }

    @Override
    public void Execute() {
        this.ui.showMessage("Please input the name of the book to reserve:");
        String bookToUpdate = this.ui.getNameOfBookToUpdate();
        try {
            this.books.updateByName(new Book(bookToUpdate, true));
            this.ui.showMessage("Thank You! Enjoy the book.");
        } catch (IllegalArgumentException e) {
            this.ui.showMessage("Sorry we don't have that book yet.");
        }
    }
}
